HAL HASH I/O operations migration ¶
This section provides information about the HAL HASH I/O operation function migration.
HAL HASH set configuration ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, a single configuration function is used to configure the peripheral for either HASH or HMAC processing modes. This function is used only in some devices. |
In HAL2, the configuration is divided into two distinct functions to separately manage the HASH and HMAC processing modes. |
HAL_StatusTypeDef HAL_HASH_SetConfig(HASH_HandleTypeDef *hhash,
const HASH_ConfigTypeDef *pConf);
|
hal_status_t HAL_HASH_SetConfig(hal_hash_handle_t *hhash,
const hal_hash_config_t *p_config);
hal_status_t HAL_HASH_HMAC_SetConfig(hal_hash_handle_t *hhash,
const hal_hash_hmac_config_t *p_config);
For more details, see HAL HASH configuration type definition |
HAL HASH retrieve configuration ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, a single configuration function is used to retrieve configuration for either HASH or HMAC processing modes. |
In HAL2, two distinct functions are provided to retrieve the configurations for HASH and HMAC separately. |
HAL_StatusTypeDef HAL_HASH_GetConfig(HASH_HandleTypeDef *hhash,
HASH_ConfigTypeDef *pConf);
|
void HAL_HASH_GetConfig(hal_hash_handle_t *hhash,
hal_hash_config_t *p_config);
void HAL_HASH_HMAC_GetConfig(hal_hash_handle_t *hhash,
hal_hash_hmac_config_t *p_config);
|
HAL HASH start for HASH/HMAC processing in polling mode ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
In HAL1, each hash algorithm has its own dedicated computing API function. |
In HAL2, the hash algorithm selection and related configuration parameters are set and managed using the HAL_HASH_SetConfig() API. p_output_size_byte is a new output parameter that explicitly returns the exact size of the computed digest. |
|
|
HASH |
HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
/* In some devices the algorithm is selected through configuration API */
HAL_StatusTypeDef HAL_HASH_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer,
uint32_t Timeout);
|
hal_status_t HAL_HASH_Compute(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
|
HMAC |
HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
/* In some devices the algorithm is selected through configuration API */
HAL_StatusTypeDef HAL_HASH_HMAC_Start(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer,
uint32_t Timeout);
|
hal_status_t HAL_HASH_HMAC_Compute(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
|
Usage example: |
uint8_t Input[3] = {0x61, 0x62, 0x63};
uint8_t Sha224output;
/* Compute HASH with SHA224 algorithm in polling mode */
HAL_HASHEx_SHA224_Start(&hhash, Input, 3, Sha224output, 1);
|
uint8_t Input[3] = {0x61, 0x62, 0x63};
/* configure the SHA224 algorithm */
hal_hash_config_t hash_cfg;
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_SHA224;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Compute HASH with SHA224 algorithm in polling mode */
HAL_HASH_Compute(&hhash, Input, 3, Sha224output, 28, &sha224output_size, 1);
|
HAL HASH start for HASH/HMAC processing using interrupt mode ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
In HAL1, each hash algorithm has its own dedicated computing API function in interrupt mode. |
In HAL2, the hash algorithm selection and related configuration parameters are set and managed using the HAL_HASH_SetConfig() API. p_output_size_byte is a new output parameter that explicitly returns the exact size of the computed digest. |
|
|
HASH |
HAL_StatusTypeDef HAL_HASH_MD5_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HASH_SHA1_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
/* In some devices the algorithm is selected via configuration API */
HAL_StatusTypeDef HAL_HASH_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer);
|
hal_status_t HAL_HASH_Compute_IT(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte);
|
|
HMAC |
HAL_StatusTypeDef HAL_HMAC_MD5_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HMAC_SHA1_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash,
uint8_t *pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash,
uint8_t *pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
/* In some devices the algorithm is selected via configuration API */
HAL_StatusTypeDef HAL_HASH_HMAC_Start_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer);
|
hal_status_t HAL_HASH_HMAC_Compute_IT(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte);
|
|
Usage example: |
uint8_t Msg3_Input[3] = {0x61, 0x62, 0x63};
uint8_t Md5output;
/* Initialize and configure the MD-5 algorithm */
hhash.Init.DataType = HASH_DATATYPE_8B;
hhash.Init.KeySize = 3;
hhash.Init.pKey = (uint8_t *)Msg3_Input;
HAL_HASH_Init(&hhash);
/* Compute HMAC MD5 in interrupt mode */
HAL_HASH_HMAC_Start_IT(&hhash, Msg3_Input, 3, Md5output);
|
uint8_t Msg3_Input[3] = {0x61, 0x62, 0x63};
uint32_t md5output_size;
/* Initialize and configure the MD-5 algorithm */
HAL_HASH_Init(&hhash);
hal_hash_config_t hash_cfg;
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_MD5;
HAL_HASH_HMAC_SetConfig(&hhash, &hash_cfg);
/* Compute HMAC MD-5 in interrupt mode */
HAL_HASH_HMAC_Compute_IT(&hhash, Msg3_Input, 3, Md5output, 16, &md5output_size, 1);
|
HAL HASH compute for HASH processing using DMA ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
In HAL1, HASH computation using DMA per hash algorithm is performed through two step separates the computation start and digest retrieval phases. |
In HAL2, these two step are merged in a single API function to compute and retrieve the computed digest output buffer. |
|
|
HASH |
start computing HAL_StatusTypeDef HAL_HASH_MD5_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASH_SHA1_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
retrieving the computed digest HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
|
hal_status_t HAL_HASH_Compute_DMA(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte);
|
|
HMAC |
start computing HAL_StatusTypeDef HAL_HMAC_MD5_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMAC_SHA1_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
retrieving the computed digest HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash,
uint8_t *pOutBuffer,
uint32_t Timeout);
|
hal_status_t HAL_HASH_HMAC_Compute_DMA(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte);
|
|
Usage example: |
uint8_t Msg3_Input[3] = {0x61, 0x62, 0x63};
uint8_t Sha224output;
/* Compute HASH MD-5 in DMA mode */
HAL_HASH_MD5_Start_DMA(&hhash, Msg3_Input, 3);
HAL_HASH_MD5_Finish(&hhash, &Sha224output, 1);
|
uint8_t Msg3_Input[3] = {0x61, 0x62, 0x63};
uint8_t Sha224output;
uint32_t md5output_size;
/* configure the MD-5 algorithm */
hal_hash_config_t hash_cfg;
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_MD5;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Compute HASH MD-5 in DMA mode */
HAL_HASH_Compute_DMA(&hhash, Msg3_Input, 3, Md5output, 16, &md5output_size);
|
HAL HASH start hashing using DMA ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
HASH |
HAL_StatusTypeDef HAL_HASH_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer);
|
hal_status_t HAL_HASH_Compute_DMA(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte);
|
|
HMAC |
HAL_StatusTypeDef HAL_HASH_HMAC_Start_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer);
|
hal_status_t HAL_HASH_HMAC_Compute_DMA(hal_hash_handle_t *hhash,
const void *p_input_buffer,
uint32_t input_size_byte,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte);
|
Note
This function is used only in some devices.
HAL HASH accumulate input data for HASH processing in polling mode ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, for multi-buffer HASH processing, feeding additional input data for each dedicated algorithm is handled through its corresponding accumulation API. The timeout management is performed internally by the HAL APIs. |
In HAL2, the hash algorithm selection is configured via HAL_HASH_SetConfig() API. In case of multi-buffer HASH processing, the update function is designed to feed additional input data to the peripheral. |
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt(HASH_HandleTypeDef *hhash,
uint8_t *pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
|
hal_status_t HAL_HASH_Update(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte,
uint32_t timeout_ms);
|
|
Usage example: /* HASH Initialization */
hhash.Init.DataType = HASH_DATATYPE_8B;
hhash.Init.pKey = Msg8192_Input;
hhash.Init.KeySize = 8192;
HAL_HASH_Init(&hhash);
/* Accumulate with SHA224 algorithm */
HAL_HASHEx_SHA224_Accmlt(&hhash, Msg8192_Input, 8000);
|
Usage example: /* HASH Initialization */
HAL_HASH_Init(&hhash);
/* Configure the SHA224 algorithm */
hal_hash_config_t hash_cfg;
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_SHA224;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Accumulate SHA224 */
HAL_HASH_Update(&hhash, Msg8192_Input, 8000, 1);
|
HAL HASH end accumulation for HASH processing in polling mode ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, providing the final additional input data to the peripheral and retrieving the computed digest is executed through the respective accumulation-end API for each hash algorithm. |
In HAL2, when processing multiple input buffers, this operation is divided into two independent function calls, clearly separating the addressing of the final input data to the peripheral from the retrieval of the resulting digest. |
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_End(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);;
HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer,
uint32_t Timeout);
|
hal_status_t HAL_HASH_Update(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte,
uint32_t timeout_ms);
hal_status_t HAL_HASH_Finish(hal_hash_handle_t *hhash,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
|
Usage example: /* HASH Initialization with 8 bits data type swapping */
hhash.Init.DataType = HASH_DATATYPE_8B;
hhash.Init.pKey = Msg8192_Input;
hhash.Init.KeySize = 8192;
HAL_HASH_Init(&hhash);
/* Accumulate end with SHA224 algorithm */
HAL_HASHEx_SHA224_Accmlt(&hhash, Msg8192_Input, 8000);
HAL_HASHEx_SHA224_Accmlt_End(&hhash, Msg8192_Input+8000, 192, Sha224output, 1);
|
Usage example: /* configure the SHA224 algorithm */
hal_hash_config_t hash_cfg;
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_SHA224;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Update and finish with SHA224 algorithm */
HAL_HASH_Update(&hhash, Msg8192_Input, 8000, 1);
HAL_HASH_Update(&hhash, Msg8192_Input+8000, 192, 1);
HAL_HASH_Finish(&hhash, Sha224output, 28, &sha244output_size, 1);
|
HAL HASH accumulate input data for HASH processing using interrupt mode ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, feeding additional input data for each dedicated algorithm is handled through its corresponding accumulation API. |
In HAL2, the hash algorithm selection is configured via the HAL_HASH_SetConfig() API. The update function is designed to feed additional input data to the peripheral. |
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
|
hal_status_t HAL_HASH_Update_IT(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
|
|
Usage example: /**/
/* Accumulate with SHA224 algorithm in IT mode */
HAL_HASHEx_SHA224_Accmlt_IT(&hhash, Msg65_Input, 60);
|
Usage example: /* configure the SHA224 algorithm */
hal_hash_config_t hash_cfg;
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_SHA224;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Accumulate with SHA224 algorithm in IT mode */
HAL_HASH_Update_IT(&hhash, Msg65_Input, 60);
|
HAL HASH end accumulation for HASH processing using interrupt mode ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, providing the final additional input data to the peripheral and retrieving the computed digest is executed through the respective accumulation-end API for each hash algorithm. |
In HAL2, when processing multiple input buffers, this operation is divided into two independent function calls, clearly separating the addressing of the final input data to the peripheral from the retrieval of the resulting digest. |
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *pOutBuffer);
|
hal_status_t HAL_HASH_Update_IT(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
hal_status_t HAL_HASH_Finish(hal_hash_handle_t *hhash,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
|
Usage example: /**/
/* Accumulate SHA224 in IT mode */
HAL_HASHEx_SHA224_Accmlt_IT(&hhash, Msg65_Input, 60, Sha224output);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
HAL_HASHEx_SHA224_Accmlt_End_IT(&hhash, Msg65_Input+60, 5, Sha224output);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
|
Usage example: /* configure the SHA224 algorithm */
hal_hash_config_t hash_cfg;
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_SHA224;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Accumulate end SHA224 algorithm */
HAL_HASH_Update_IT(&hhash, Msg8192_Input, 8000);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
HAL_HASH_Update_IT(&hhash, Msg8192_Input+8000, 192);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
HAL_HASH_Finish(&hhash, Sha224output, 28, &sha244output_size, 1);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
|
HAL HASH accumulate input data for HASH/HMAC processing ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
HASH |
HAL_StatusTypeDef HAL_HASH_Accumulate(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint32_t Timeout);
|
hal_status_t HAL_HASH_Update(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte,
uint32_t timeout_ms);
|
|
HMAC |
HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint32_t Timeout);
|
hal_status_t HAL_HASH_HMAC_Update(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte,
uint32_t timeout_ms);
|
Note
This function is used only in some devices.
HAL HASH accumulate the last input data block for HASH/HMAC processing ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
HASH |
HAL_StatusTypeDef HAL_HASH_AccumulateLast(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer,
uint32_t Timeout);
|
hal_status_t HAL_HASH_Update(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte,
uint32_t timeout_ms);
hal_status_t HAL_HASH_Finish(hal_hash_handle_t *hhash,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
|
HMAC |
HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer,
uint32_t Timeout);
|
hal_status_t HAL_HASH_HMAC_Update(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte,
uint32_t timeout_ms);
hal_status_t HAL_HASH_HMAC_Finish(hal_hash_handle_t *hhash,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
Note
This function is used only in some devices.
HAL HASH accumulate input data for HASH/HMAC processing using interrupt mode ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
HASH |
HAL_StatusTypeDef HAL_HASH_Accumulate_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
|
hal_status_t HAL_HASH_Update_IT(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
|
|
HMAC |
HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
|
hal_status_t HAL_HASH_HMAC_Update_IT(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
|
Note
This function is used only in some devices.
HAL HASH accumulate the last input data block for HASH/HMAC processing using interrupt mode ¶
|
Process |
HAL1 |
HAL2 |
|---|---|---|
|
HASH |
HAL_StatusTypeDef HAL_HASH_AccumulateLast_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer);
|
hal_status_t HAL_HASH_Update_IT(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
hal_status_t HAL_HASH_Finish(hal_hash_handle_t *hhash,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
|
HMAC |
HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast_IT(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size,
uint8_t *const pOutBuffer);
|
hal_status_t HAL_HASH_HMAC_Update_IT(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
hal_status_t HAL_HASH_HMAC_Finish(hal_hash_handle_t *hhash,
void *p_output_buffer,
uint32_t output_buffer_size_byte,
uint32_t *p_output_hash_size_byte,
uint32_t timeout_ms);
|
Note
This function is used only in some devices.
HAL HASH perform HMAC multi-buffers processing using DMA ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, multi-buffer computation using DMA is performed in predefined steps. Each step processes a fixed portion of data sequentially. |
In HAL2, multi-buffer processing supports incremental updates of the ongoing computation by continuously feeding additional input data through DMA. The function HAL_HASH_HMAC_Update_DMA allows you to update the current HMAC calculation by processing new input data via DMA |
|
first start-up the multi-buffer with the first input data HAL_StatusTypeDef HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
next fed to the peripheral HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
feeding the last input buffer to the peripheral HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef *hhash,
const uint8_t *const pInBuffer,
uint32_t Size);
|
first start-up the multi-buffer with the first input data hal_status_t HAL_HASH_HMAC_Update_DMA(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
/**/
/**/
next fed to the peripheral hal_status_t HAL_HASH_HMAC_Update_DMA(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
/**/
/**/
feeding the last input buffer to the peripheral hal_status_t HAL_HASH_HMAC_Update_DMA(hal_hash_handle_t *hhash,
const void *p_add_input_buffer,
uint32_t input_size_byte);
|
|
usage example uint8_t Input[261] =
{0x54,0x68,0x65,0x20,0x68,0x61,0x73,0x68,
.....,
0x2a,0x2a,0x2a,0x20,0x53,0x54,0x4d,0x33};
/* HASH initialization with HMAC SHA224 digest computation */
hhash.Init.DataType = HASH_DATATYPE_8B;
hhash.Init.pKey = Input;
hhash.Init.KeySize = 261;
HAL_HASH_Init(&hhash);
/* HMAC digest computation with multi-buffers in DMA mode */
HAL_HMACEx_SHA224_Step1_2_DMA(&hhash, aInput, 64);
while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
HAL_HMACEx_SHA224_Step2_DMA(&hhash, aInput+64, 64);
while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
HAL_HMACEx_SHA224_Step2_DMA(&hhash, aInput+192, 64);
while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
HAL_HMACEx_SHA224_Step2_3_DMA(&hhash, aInput+256, 5);
while (HAL_HASH_GetState(&HashHandle) == HAL_HASH_STATE_BUSY);
HAL_HASHEx_SHA224_Finish(&hhash, Sha2output, 1000);
|
usage example uint8_t Input[261] =
{0x54,0x68,0x65,0x20,0x68,0x61,0x73,0x68,
.....,
0x2a,0x2a,0x2a,0x20,0x53,0x54,0x4d,0x33};
/* HASH initialization and Configure SHA224 algorithm */
HAL_HASH_Init(&hhash, HAL_HASH);
hash_hmac_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_hmac_cfg.algorithm = HAL_HASH_ALGO_SHA224;
hash_hmac_cfg.key_size_byte = 261;
hash_hmac_cfg.p_key = aInput;
HAL_HASH_HMAC_SetConfig(&hhash, &hash_hmac_cfg);
/* HMAC digest computation with multi-buffers in DMA mode */
HAL_HASH_HMAC_Update_DMA(&hhash, aInput, 64);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
HAL_HASH_HMAC_Update_DMA(&hhash, aInput+64, 64);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
HAL_HASH_HMAC_Update_DMA(&hhash, aInput+192, 64);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
HAL_HASH_HMAC_Update_DMA(&hhash, aInput+256, 5);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
HAL_HASH_Finish(&hhash, 28, &Sha2output, 1000);
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
|
HAL HASH suspend the HASH process ¶
|
HAL1 |
HAL2 |
|---|---|
|
HAL2 uses separate suspension operation functions depending on whether the processing is in oneshot or multi-buffer update modes. |
|
HAL_StatusTypeDef HAL_HASH_ProcessSuspend(HASH_HandleTypeDef *hhash);
|
Oneshot computation hal_status_t HAL_HASH_RequestSuspendComputation(hal_hash_handle_t *hhash);
Update computation with multiple input buffers hal_status_t HAL_HASH_RequestSuspendUpdate(hal_hash_handle_t *hhash);
|
Related use case: Use case: HASH process suspending and resuming in IT mode
HAL HASH resume the HASH process ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, resuming and restoring the hash computation context are handled through a single API function. |
In HAL2, whether for one-shot or multi-buffer processing, the resuming operation is divided into two distinct steps: one for resuming the process itself and another for restoring the context to the handle. |
void HAL_HASH_Resume(HASH_HandleTypeDef *hhash,
uint8_t *pMemBuffer);
|
Oneshot computation hal_status_t HAL_HASH_ResumeComputation(hal_hash_handle_t *hhash);
void HAL_HASH_RestoreContext(hal_hash_handle_t *hhash,
const hal_hash_suspended_context_t *p_context);
Update computation with multiple input buffers hal_status_t HAL_HASH_ResumeUpdate(hal_hash_handle_t *hhash);
void HAL_HASH_RestoreContext(hal_hash_handle_t *hhash,
const hal_hash_suspended_context_t *p_context);
|
Related use case: Use case: HASH process suspending and resuming in IT mode
HAL HASH suspend process ¶
|
HAL1 |
HAL2 |
|---|---|
|
In HAL1, suspension and saving the hash computation context are handled through a single API function. |
In HAL2, whether for one-shot or multi-buffer processing, the suspension operation is divided into two distinct steps: one for suspension the process itself and another for saving the context to the handle. |
void HAL_HASH_Suspend(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer);
|
hal_status_t HAL_HASH_RequestSuspendComputation(hal_hash_handle_t *hhash);
void HAL_HASH_SaveContext(hal_hash_handle_t *hhash,
hal_hash_suspended_context_t *p_context);
|
HAL HASH suspend software feed process ¶
|
HAL1 |
HAL2 |
|---|---|
|
HAL2 uses a separate request to suspend the computation operation depending on whether the processing is in one-shot or multi-buffer update modes. |
|
void HAL_HASH_SwFeed_ProcessSuspend(HASH_HandleTypeDef *hhash);
|
Oneshot computation hal_status_t HAL_HASH_RequestSuspendComputation(hal_hash_handle_t *hhash);
Update computation with multiple input buffers hal_status_t HAL_HASH_RequestSuspendUpdate(hal_hash_handle_t *hhash);
|
HAL HASH restore the HASH context ¶
|
HAL1 |
HAL2 |
|---|---|
void HAL_HASH_ContextRestoring(HASH_HandleTypeDef *hhash,
const uint8_t *pMemBuffer);
|
void HAL_HASH_RestoreContext(hal_hash_handle_t *hhash,
const hal_hash_suspended_context_t *p_context);
|
HAL HASH save the HASH context ¶
|
HAL1 |
HAL2 |
|---|---|
void HAL_HASH_ContextSaving(HASH_HandleTypeDef *hhash,
uint8_t *pMemBuffer);
|
void HAL_HASH_SaveContext(hal_hash_handle_t *hhash,
hal_hash_suspended_context_t *p_context);
|
Related use case: Use case: HASH process suspending and resuming in IT mode
HAL HASH suspend the DMA feed process ¶
|
HAL1 |
HAL2 |
|---|---|
|
HAL2 uses separate request to suspend the computation operation in DMA mode depending on whether the processing is in oneshot or multi-buffer update modes |
|
HAL_StatusTypeDef HAL_HASH_DMAFeed_ProcessSuspend(HASH_HandleTypeDef *hhash);
|
Oneshot computation hal_status_t HAL_HASH_RequestSuspendComputation(hal_hash_handle_t *hhash);
Update computation with multiple input buffers hal_status_t HAL_HASH_RequestSuspendUpdate(hal_hash_handle_t *hhash);
|